package com.enjoy.factory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class SpringApplication implements ApplicationContextAware {

    protected static final Logger log = LoggerFactory.getLogger(SpringApplication.class);

    static ApplicationContext app;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        app = applicationContext;
        log.info("Init SpringApplication for Static call...");
    }


    public static Object getBean(String name) {
        return app.getBean(name);
    }


    public static <Service>Service getBean(Class<Service> clazz) {
        return app.getBean(clazz);
    }
}
